package States;

import java.util.ArrayList;
import java.util.Iterator;

import GUI.IntroducereDateLupCapraVarza;
import Operators.FarmerOperators.InitialState;
import Templates.State;

public class FarmerStates {
	private int leftWolf =0;
	private int leftSheep =0;
	private int leftCabbage =0;
	private int leftFarmer =0;
	private int rightWolf =0;
	private int rightSheep =0;
	private int rightCabbage =0;
	private int rightFarmer =0;
	
	private static ArrayList<String> dateLCV;
	
	
	public static State<FarmerStates> initalState()
	{
		dateLCV = IntroducereDateLupCapraVarza.date;
		Iterator<String> itr =  dateLCV.iterator();
		int[] v = new int[6];
		int i=0;
	    while(itr.hasNext()) {
	         String element = itr.next();
	         System.out.print(" " + i + " : " + element);
	         if(element.equals("true"))
	        	 v[i++] = 1;
	         else
	        	 v[i++] = 0;
	    }
	    System.out.println();
	    
		return new State<FarmerStates>(new FarmerStates(v[0], v[1], v[2], 0, v[3], v[4], v[5], 1),new InitialState() );
	}
	
	public static ArrayList<State<FarmerStates>> finalStates()
	{
		ArrayList<State<FarmerStates>> fStates=new ArrayList<State<FarmerStates>>();
		fStates.add(new State<FarmerStates>(new FarmerStates(1,1,1,1,0,0,0,0),null));
		return fStates;
	}	
	public FarmerStates(FarmerStates s)
	{
		this.leftWolf = s.leftWolf;
		this.leftSheep = s.leftSheep;
		this.leftCabbage = s.leftCabbage;
		this.leftFarmer = s.leftFarmer;
		this.rightWolf = s.rightWolf;
		this.rightSheep = s.rightSheep;
		this.rightCabbage = s.rightCabbage;
		this.rightFarmer = s.rightFarmer;
	}
	
	public FarmerStates(int leftWolf, int leftSheep, int leftCabbage,
			int leftFarmer, int rightWolf, int rightSheep, int rightCabbage,
			int rightFarmer) {
		super();
		this.leftWolf = leftWolf;
		this.leftSheep = leftSheep;
		this.leftCabbage = leftCabbage;
		this.leftFarmer = leftFarmer;
		this.rightWolf = rightWolf;
		this.rightSheep = rightSheep;
		this.rightCabbage = rightCabbage;
		this.rightFarmer = rightFarmer;
	}
	
	public int getLeftWolf() {
		return leftWolf;
	}
	public void setLeftWolf(int leftWolf) {
		this.leftWolf = leftWolf;
	}
	public int getLeftSheep() {
		return leftSheep;
	}
	public void setLeftSheep(int leftSheep) {
		this.leftSheep = leftSheep;
	}
	public int getLeftCabbage() {
		return leftCabbage;
	}
	public void setLeftCabbage(int leftCabbage) {
		this.leftCabbage = leftCabbage;
	}
	public int getLeftFarmer() {
		return leftFarmer;
	}
	public void setLeftFarmer(int leftFarmer) {
		this.leftFarmer = leftFarmer;
	}
	public int getRightWolf() {
		return rightWolf;
	}
	public void setRightWolf(int rightWolf) {
		this.rightWolf = rightWolf;
	}
	public int getRightSheep() {
		return rightSheep;
	}
	public void setRightSheep(int rightSheep) {
		this.rightSheep = rightSheep;
	}
	public int getRightCabbage() {
		return rightCabbage;
	}
	public void setRightCabbage(int rightCabbage) {
		this.rightCabbage = rightCabbage;
	}
	public int getRightFarmer() {
		return rightFarmer;
	}
	public void setRightFarmer(int rightFarmer) {
		this.rightFarmer = rightFarmer;
	}
	public String toString()
	{
		String leftSide="";
		
		if (leftWolf==1) 
			leftSide+=" L " ;
		else
			leftSide+=" _ ";
		if (leftSheep==1) 
			leftSide+=" C ";
		else
			leftSide+=" _ ";
		if (leftCabbage==1) 
			leftSide+=" V ";
		else
			leftSide+=" _ ";
		if (leftFarmer==1) 
			leftSide+=" B ";
		else
			leftSide+=" _ ";
		
		String rightSide="";
		
		if (rightWolf==1) 
			rightSide+=" L ";
		else
			rightSide+=" _ ";
		if (rightSheep==1) 
			rightSide+=" C ";
		else
			rightSide+=" _ ";
		if (rightCabbage==1) 
			rightSide+=" V ";
		else
			rightSide+=" _ ";
		if (rightFarmer==1) 
			rightSide+=" B ";
		else
			rightSide+=" _ ";
		return leftSide + " |............| " +rightSide;	
	}
	
}
